
<?php
ini_set("error_reporting", E_ALL);
$pdo = new PDO("mysql:host=qdm170029222.my3w.com;dbname=qdm170029222_db", "qdm170029222", "xq19900719");
$pdo->query("SET NAMES utf8");

$name = $text = $ip = $num = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_GET["name"]);
  $text = test_input($_GET['text']);
  $num = test_input($_GET['num']);
  $ip = $_SERVER['REMOTE_ADDR'];
  $name0 = $_GET["name0"]?$_GET["name0"]:$_SERVER['REMOTE_ADDR'];
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

if (empty($name) || empty($text)) {
    return false;
}
$result = array(
    "success" => false
);
if ($pdo->exec("INSERT INTO bless SET name = '$name', text = '$text',ip = '$ip',num='$num',name0='$name0', create_time = NOW() ")) {
    $result['success'] = true;
}
echo json_encode($result);


// if (!$conn) {
//     die("Connection failed: " . mysqli_connect_error());
// }

// $sql = "INSERT INTO MyGuests (firstname, lastname, email)
// VALUES ('John', 'Doe', 'john@example.com')";

// if (mysqli_query($conn, $sql)) {
//     echo "新记录插入成功";
// } else {
//     echo "Error: " . $sql . "<br>" . mysqli_error($conn);
// }

// mysqli_close($conn);